<!DOCTYPE RCC>
<RCC version="1.0"/>

#include "RegisterDialog.h"

RegisterDialog::RegisterDialog(QWidget *parent) : QDialog(parent) {
    setWindowTitle("用户注册");

    // 创建标签和输入框
    QLabel *usernameLabel = new QLabel("用户名:");
    usernameInput = new QLineEdit();

    QLabel *passwordLabel = new QLabel("密码:");
    passwordInput = new QLineEdit();
    passwordInput->setEchoMode(QLineEdit::Password);

    QLabel *confirmPasswordLabel = new QLabel("确认密码:");
    confirmPasswordInput = new QLineEdit();
    confirmPasswordInput->setEchoMode(QLineEdit::Password);

    // 创建按钮
    QPushButton *registerButton = new QPushButton("注册");
    QPushButton *cancelButton = new QPushButton("取消");

    // 连接信号和槽
    connect(registerButton, &QPushButton::clicked, this, &RegisterDialog::onRegisterButtonClicked);
    connect(cancelButton, &QPushButton::clicked, this, &RegisterDialog::reject);

    // 布局设置
    QVBoxLayout *layout = new QVBoxLayout();
    layout->addWidget(usernameLabel);
    layout->addWidget(usernameInput);
    layout->addWidget(passwordLabel);
    layout->addWidget(passwordInput);
    layout->addWidget(confirmPasswordLabel);
    layout->addWidget(confirmPasswordInput);
    layout->addWidget(registerButton);
    layout->addWidget(cancelButton);
    setLayout(layout);
}

void RegisterDialog::onRegisterButtonClicked() {
    QString username = usernameInput->text();
    QString password = passwordInput->text();
    QString confirmPassword = confirmPasswordInput->text();

    // 检查输入有效性
    if (username.isEmpty() || password.isEmpty()) {
        QMessageBox::warning(this, "错误", "用户名和密码不能为空！");
        return;
    }
    if (password != confirmPassword) {
        QMessageBox::warning(this, "错误", "密码和确认密码不一致！");
        return;
    }
    if (password.length() < 6) {
        QMessageBox::warning(this, "错误", "密码长度至少为6位！");
        return;
    }

    // 注册成功提示
    QMessageBox::information(this, "注册成功", "注册成功，请返回登录！");
    accept();
}
